package com.v1.video.wxapi;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.v1.video.activity.BaseActivity;
import com.v1.video.pay.Key;
import com.v1.video.pay.WeixinUtils;

public class WXPayEntryActivity extends BaseActivity implements
		IWXAPIEventHandler {

	private static final String TAG = "WXPayEntryActivity";

	private IWXAPI mApi;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mApi = WXAPIFactory.createWXAPI(this, Key.WX_APP_ID);
		mApi.handleIntent(getIntent(), this);
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
		mApi.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
		
	}

	@Override
	public void onResp(BaseResp resp) {
		Log.d(TAG, "onPayFinish, errCode = " + resp.errCode + ", errStr= "
				+ resp.errStr);
		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
			if (WeixinUtils.getmOnPayListener() != null) {
				WeixinUtils.getmOnPayListener().onPayListener(resp.errCode);
			}
		}
		this.finish();
	}
}